home *** CD-ROM | disk | FTP | other *** search
- %
- % circtext.ps - render text strings around arcs
- %
- % From Adobe Cookbook
- % Program: Circular Text Number: 16
- %-----------------------------------------------------------------------------
- %
- /outsidecircletext % outsidecircletext places text
- { $circtextdict begin % around a circular arc. The
- /radius exch def % baseline of the text is placed
- /centerangle exch def % on the outside of the
- /ptsize exch def % circumference of the circle in a
- /str exch def % clockwise fashion.
- % outsidecircletext takes four
- % arguments: the string to be
- % printed, the point size of the
- % font being used, the angle
- % around which the text should be
- % centered and the radius of the
- % circular arc. It assumes that
- % the center of the circle is at
- % (0,0).
- /xradius radius ptsize 4 div add % A radius that is slightly larger
- def % than the one specified is used
- % for computations but not for
- % placement of characters. Using a
- % slightly larger radius in the
- % computations places the
- % characters closer together,
- % otherwise the interletter
- % spacing is too loose.
- gsave % Save the current graphics state.
- centerangle str findhalfangle % Find out how much angle the
- add rotate % string subtends and then rotate
- % to the appropriate starting
- % position for showing the string.
- % (The positive x-axis now
- % intersects the circle where the
- % text should start.)
- str
- { /charcode exch def % For each character in the
- ( ) dup 0 charcode put % string, determine its position
- outsideshowcharandrotate % on the circular arc and show it.
- } forall
- grestore % Return to the former graphics
- % state.
- end
- } def
-
- /insidecircletext % insidecircletext works very
- { $circtextdict begin % similarly to outsidecircletext
- /radius exch def % except that the baseline of the
- /centerangle exch def % text is placed on the inside of
- /ptsize exch def % the circumference of the circle
- /str exch def % in a counter-clockwise fashion.
- % insidecircletext takes the same
- % four arguments as
- % outsidecircletext.
-
- /xradius radius ptsize 3 div sub % Here we use a radius which is
- def % slightly smaller than the
- % desired radius for computations.
- % This forces the characters to be
- % placed farther apart to avoid
- % overlapping.
- gsave
- centerangle str findhalfangle
- sub rotate
- str
- { /charcode exch def
- ( ) dup 0 charcode put
- insideshowcharandrotate
- } forall
- grestore
- end
- } def
- /$circtextdict 16 dict def
- $circtextdict begin
- /findhalfangle % findhalfangle takes one
- { stringwidth pop 2 div % argument, a string, and finds
- 2 xradius mul pi mul div 360 mul % the angle subtended by that
- } def % string. It leaves the value of
- % half of that angle on the stack.
- % The angle is found by computing
- % the ratio of the width of the
- % string to the circumference of
- % the circle and then converting
- % that value to degrees.
-
- /outsideshowcharandrotate % This procedure shows a character
- { /char exch def % upright on the outside of the
- /halfangle char findhalfangle def % circumference and then rotates
- gsave % clockwise by the amount of angle
- % subtended by the width of the
- % character.
- halfangle neg rotate % Rotate clockwise by half the
- radius 0 translate % angle taken up by the width of
- % the character and translate out
- % to the circumference.
- -90 rotate % Position character upright on
- % outside of circumference.
- char stringwidth pop 2 div neg % Center the character around the
- % origin.
- 0 moveto char show
- grestore
- halfangle 2 mul neg rotate % Rotate clockwise by the amount
- } def % of angle subtended by the width
- % of the character.
-
- /insideshowcharandrotate % insideshowcharandrotate operates
- { /char exch def % in a similar manner to
- /halfangle char findhalfangle def % outsideshowcharandrotate except
- gsave % that the direction of rotation
- halfangle rotate % is counter-clockwise and the
- radius 0 translate % characters are placed upright on
- 90 rotate % the inside of the circle.
- char stringwidth pop 2 div neg
- 0 moveto char show
- grestore
- halfangle 2 mul rotate
- } def
-
- /pi 3.1415923 def
- end
-
- % Don't need to print out this example for use as a library:
- %/Times-Bold findfont 15 scalefont setfont
- %306 448 translate
- %(Symphony No. 9 (from the New World))
- % 15 90 100 outsidecircletext
- %/Times-Roman findfont 10 scalefont setfont
- %(Antonin Dvorak)
- % 10 90 84 outsidecircletext
- %(The New York Philharmonic Orchestra)
- % 10 270 84 insidecircletext
- %showpage
-